import java.awt.*;
import java.awt.geom.*;

public class Ball extends Ellipse2D.Double
{
	private double xPos, yPos;
	private int x_speed, y_speed;
	private int radius;
	
	private static int setLevel = 1;
	
	private boolean death = false;
	
	private Map level, end;
	private Bomb[] bombs;
	private Mover[] flash;
	
	public Ball (int radius, double startX, double startY, double startWidth, double startHeight)
	{
		super ((int) (startX + startWidth - startWidth / 2 - (radius / 2)), (int) (startY + startHeight - startHeight / 2 - (radius / 2)), radius, radius);

		this.xPos = super.x;
		this.yPos = super.y;
		this.radius = radius;
	}


	public void move ()
	{
		super.x += x_speed;     // Continously adds the x speed to the x position of the ball
		super.y += y_speed;     // Continously adds the y speed to the y postion of the ball

		Game.graphics.setColor (Color.MAGENTA);
		Game.graphics.fill (this);
	}

	public void detect ()
	{
		if (Map.line(level.getX(), level.getY(), level.getX() + level.getWidth(), level.getY()).intersects(this.getBounds()))
			super.y = level.getY();
		if (Map.line(level.getX(), level.getY() + level.getHeight(), level.getX() + level.getWidth(), level.getY() + level.getHeight()).intersects(this.getBounds()))
			super.y = level.getY() + level.getHeight() - radius;
		if (Map.line(level.getX(), level.getY(), level.getX(), level.getY() + level.getHeight()).intersects(this.getBounds()))
			super.x = level.getX();
		if (Map.line(level.getX() + level.getWidth(), level.getY(), level.getX() + level.getWidth(), level.getY() + level.getHeight()).intersects(this.getBounds()))
			super.x = level.getX() + level.getWidth() - radius;
		
		if (end.contains(super.getBounds()))
		{
			Game.setLevel();
		}
		
		/*if (setLevel == 1)
		{
			for (int i = 0; i < 11; i++)
			{
				if (bombs[i].getBounds().intersects(super.getBounds()) && Game.increment())
				{			
					super.x = this.xPos;
					super.y = this.yPos;
					
					death = true;
				}
			}
		}
		
		else*/ if (setLevel == 2)
		{
			for (int i = 0; i < 12; i++)
			{
				if (flash[i].getBounds().intersects(super.getBounds()))
				{
					super.x = this.xPos;
					super.y = this.yPos;
					
					death = true;
				}
			}
		}

	}

	public void setYSpeed (int ySpeed)
	{
		y_speed = ySpeed;
	}


	public void setXSpeed (int xSpeed)
	{
		x_speed = xSpeed;
	}
	
	public void reference (Map level, Map end, Bomb[] bombs)
	{
		this.level = level;
		this.end = end;
		this.bombs = bombs;
	}
	
	public void reference (Map level, Map end, Mover[] flash)
	{
		this.level = level;
		this.end = end;
		this.flash = flash;
	}
	
	public boolean getDeath ()
	{
		return death;
	}
	
	public void setDeath (boolean death)
	{
		this.death = death;
	}
	
	public static void setLevel (int level)
	{
		setLevel = level;
	}
}